# aarch64-linux-gnu具链定义
# author guyadong
# date 2023/09/21
SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv8)

if(NOT $ENV{CROSS_COMPILER_PREFIX} STREQUAL "")
    set(_compiler_prefix $ENV{CROSS_COMPILER_PREFIX})
elseif(CROSS_COMPILER_PREFIX)
    set(_compiler_prefix ${CROSS_COMPILER_PREFIX})
else()
	find_program(_gcc_path aarch64-linux-gnu-gcc)
	if(NOT _gcc_path)
		message(FATAL_ERROR "NOT FOUND compiler aarch64-linux-gnu-gcc in system path")
	endif()
	get_filename_component(_compiler_prefix ${_gcc_path} DIRECTORY )
endif()	
message(STATUS _compiler_prefix=${_compiler_prefix})
# Specify the cross compiler
SET(CMAKE_C_COMPILER "${_compiler_prefix}aarch64-linux-gnu-gcc")
SET(CMAKE_CXX_COMPILER "${_compiler_prefix}aarch64-linux-gnu-g++")
SET(CMAKE_ASM_COMPILER "${_compiler_prefix}aarch64-linux-gnu-gcc")

# Search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# For libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

unset(_compiler_prefix)